package com.kgc.scd.controller;

import com.kgc.scd.bean.ShopAttribute;
import com.kgc.scd.bean.ShopCarousel;
import com.kgc.scd.bean.ShopGoods;
import com.kgc.scd.mapper.ShopAttributeMapper;
import com.kgc.scd.service.GoodsInfoCommentService;
import com.kgc.scd.util.PageSupport;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.ResultBuildUtil;
import com.kgc.scd.vo.ShopCarouselVO;
import com.kgc.scd.vo.ShopCommentVO;
import com.kgc.scd.vo.ShopGoodsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Created On : 2022/11/14.
 * <p>
 * Author : 22166
 * <p>
 * Description: CommentController
 */
@Slf4j
@RestController
@Api(value = "操作入口")
public class GoodsCommentController {

    @Autowired(required = false)
    private GoodsInfoCommentService goodsInfoCommentService;

    @Autowired(required = false)
    private ShopAttributeMapper shopAttributeMapper;

    /**
     * @author : 22166
     * @date   : 2022/11/15
     * @param  : [goodsId]
     * @return : com.kgc.scd.vo.ShopGoodsVO
     * @description : 查询商品详情
     */
    @GetMapping("/shopGoods")
    public ShopGoodsVO shopGoods(@RequestParam String goodsId){

        return goodsInfoCommentService.selectGoodsInfo(goodsId);

    }



    /**
     * @author : 22166
     * @date   : 2022/11/17
     * @param  : [goodsid]
     * @return : int
     * @description : 在shop+comment表中根据goodsId查询商品评论总数
     */
    @GetMapping("/getCommentSum")
    public int getCommentSum(@RequestParam String goodsId){

        return goodsInfoCommentService.getShoppingCommentSum(goodsId);
    }


    /**
     * @author : 22166
     * @date   : 2022/11/14
     * @param  : [pageNo, pageSize]
     * @return : com.kgc.scd.util.RequestResult<java.util.List<com.kgc.scd.bean.ShopCommentVO>>
     * @description : 查询评论列表带分页
     */
    @GetMapping("/goodsCommentList")
    public PageSupport<ShopCommentVO> goodsCommentList(@RequestParam(name = "goodsId") String goodsId,
                                                       @RequestParam(name = "pageNo") Integer pageNo,
                                                       @RequestParam(name = "pageSize") Integer pageSize){

        //PageSupport<List<ShopCommentVO>> list =goodsInfoCommentService.getCommentListPage(goodsId,pageNo,pageSize);

        // 调用业务接口，查询评论详情
        return goodsInfoCommentService.getCommentListPage(goodsId,pageNo,pageSize);


    }
    
    
    
    /**
     * @author : 22166
     * @date   : 2022/11/15
     * @param  : []
     * @return : JSONResult
     * @description : 获取轮播图
     */
    @GetMapping("/carousel")
    @ApiOperation(value = "获取首页轮播图",notes = "获取首页轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品id")
    })
    public List<ShopCarouselVO> carousel(){


        return goodsInfoCommentService.queryAll();
    }
    /**
     * @author : 崔佳伟
     * @date   : 2022/11/23
     * @param  : [goodsId]
     * @return : java.util.List<com.kgc.scd.bean.ShopAttribute>
     * @description : 根据商品id查询商品对应参数
     */
    @GetMapping("/selectAttribute")
    public List<ShopAttribute> select2ShopAttribute(@RequestParam String goodsId){

        return shopAttributeMapper.selectShopAttribute(goodsId);

    }

    /**
     * @author : 崔佳伟
     * @date   : 2022/11/23
     * @param  : [id, goodsId]
     * @return : int
     * @description : 修改轮播图对应商品根据id
     */
    @PostMapping("/update")
    @ApiOperation(value = "更新",notes = "更新")
    public int update(String id,String goodsId){
        return goodsInfoCommentService.updateShopCarousel(id,goodsId);
    }


}